﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Zyg.Utility.Helper;
using Zyg.SSO.Core.Business;

namespace Zyg.SSO.Web.Admin.App
{
    public partial class AppAccountUsers : Zyg.SSO.Web.BasePage
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!Page.IsPostBack)
            {
                if (!base.Account.HavePermission(Permission.AppManage))
                {
                    throw new Exception("你无权查看此页面");
                }
                bool parseSucceed;

                Guid accountAppId = Request.QueryString["accountAppId"].ToGuid(out parseSucceed);

                if (parseSucceed)
                {
                    BindData(accountAppId);
                }
                else
                {
                    throw new Exception("对不起，你所访问的页面不存在");
                }
            }
        }

        private void BindData(Guid accountAppId)
        {
            AccountApp accountApp = AccountApp.Load(accountAppId);

            if (accountApp == null)
                throw new Exception("对不起，你所访问的页面不存在");

            AccountEmail.Text = accountApp.Account.Email;
            AppName.Text = accountApp.App.Name;
            AddAppTime.Text = accountApp.DateCreated.ToString("yyyy年MM月dd日 H点mm分");

            IList<AccountAppUser> aaus = new List<AccountAppUser>();

            for (int i = accountApp.Users.Count - 1; i > -1; i--)
            {
                aaus.Add(accountApp.Users[i]);
            }

            GridViewAccountAppUsers.DataSource = aaus;
            GridViewAccountAppUsers.DataBind();
        }
    }
}
